//
//  LTDBHelper.h
//  LTIM
//
//  Created by 俊松何 on 2017/3/28.
//  Copyright © 2017年 俊松何. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "LTMessage.h"

@class LTMessage, LTUserModel,LTUser,LTGroup,LTUserConfig,LTGroupConfig,LTSearchResultModel,LTError,LTConversation,LTMessageApplyBody;

//一下这些操作都是线程安全的
@interface LTDBHelper : NSObject

+(instancetype)sharedbhelper;
-(void)initDB;
-(void)CloseDB;

//保存端口号和IP
-(void)saveVersionInfoWithIP:(NSString *)ip port:(NSString *)port;

//得到版本信息
-(void)getVersionInfoWithcompletion:(void (^)(NSString *ip, NSString *port))completionBlock;

//添加一个会话
-(BOOL)AddConversation:(LTConversation *)conversation;

//删除一个会话
-(BOOL)DeleteConversationWithConversationID:(NSString *)conversationId;

//删除一个会话  isdelete 是否删除所有消息
-(BOOL)DeleteConversationWithConversationID:(NSString *)conversationId  deleteMessage:(BOOL)isdelete;

//会话id下的所有会话标记为已读
-(void)markAllMessagesAsReadWithConversationID:(NSString *)conversationId;
//标记这个消息id的消息为已读
-(BOOL)markMessagesAsReadWithMessageId:(NSString *)MessageId;

//得到所有会话
-(NSArray<LTConversation *> *)getAllConversation;

//得到一条会话
-(LTConversation *)getConversationWithConversationID:(NSString *)conversationId;


- (BOOL)markConversationID:(NSString *)conversation isTop:(BOOL)istop;


- (BOOL)markConversationID:(NSString *)conversation isSilent:(BOOL)isSilent;




//得到所有未读会话数
-(NSInteger)getAllUnreadMessage;
//得到会话id未读的会话数
-(NSInteger)getUnreadMessageWithConversationID:(NSString *)conversationId;

//得到会话id未读的At消息数
-(NSInteger)getAtUnreadMessageWithConversationID:(NSString *)conversationId;


//该回话下所有未读AT消息
-(NSArray<LTMessage *> *)getAtUnReadMessageConversationID:(NSString *)conversation;


//消息操作
-(BOOL)AddMessage:(LTMessage *)message;

- (void)updateMessage:(LTMessage *)Message
           completion:(void (^)(LTMessage *aMessage, LTError *aError))CompletionBlock;

//添加一组消息
-(BOOL)addMessages:(NSArray<LTMessage *> *)messages;

//得到会话的最后一条消息
-(LTMessage *)getlastMessageWithConversationID:(NSString *)conversationID;
//获取到会话的所有消息
-(NSArray<LTMessage *> *)getMessageWithConversation:(NSString *)conversation;

//获取指定时间戳开始的count条消息
-(NSArray<LTMessage *> *)getMessageWithConversation:(NSString *)conversation
                                          startTime:(double)time
                                              count:(int)count;

//获取指定时间戳开始的count条消息
-(void)getMessageWithConversation:(NSString *)conversation
                                          startTime:(double)time
                                              count:(int)count
                                         completion:(void (^)(NSArray<LTMessage *> *aMessages, LTError *aError))aCompletionBlock;

-(void)getmessageWithConversation:(NSString *)conversation
                        messageId:(NSString *)messageId
                            count:(int)count
                       completion:(void (^)(NSArray<LTMessage *> *aMessages, LTError *aError))aCompletionBlock;


-(BOOL)deleteMessageWithMessageId:(NSString *)messageId;

-(BOOL)deleteMessageWithConversation:(NSString *)conversationId;




//用户好友操作
-(BOOL)AddUser:(LTUser *)user;

-(BOOL)deleteUser:(NSString *)userID;

-(LTUser *)getUserWithUserId:(NSString *)userId;

-(NSArray<LTUser *> *)getFriendUser;

-(void)updateUser:(NSArray *)userArray;

-(BOOL)isFriendWithUserId:(NSString *)userId;

-(BOOL)isFriendWithAccount:(NSString *)account;





//添加一条申请消息
-(BOOL)addApplyMessage:(LTMessageApplyBody *)applyMessage;

//删除一个user的申请消息
-(BOOL)deleteAppleMessageFromSinceUserId:(NSString *)sinceUserId;

//删除一条申请消息
-(BOOL)deleteAppleMessage:(NSString *)applyMessageId;

//添加一组消息
-(BOOL)addApplyMessages:(NSArray<LTMessageApplyBody *> *)applyMessages;


//得到所有的操作
-(NSArray<LTMessageApplyBody *> *)getAllApplyWithUserID:(NSString *)sinceUserID;

//得到所有未读会话数
-(NSInteger)getAllUnreadApplyMessage;

//标记所有申请消息为已读    ---------
-(BOOL)markAllApplyMessagesAsRead;




//小红点操作

-(BOOL)addNoticeMessageWithType:(LTNoticeMessageType)type;

-(BOOL)deleteNoticeMessageWithType:(LTNoticeMessageType)type;

-(NSInteger)getUnradNoticeMessageWithType:(LTNoticeMessageType)type;


//群组操作
-(BOOL)AddGroup:(LTGroup *)group;
//删除群组
-(BOOL)deleteGroup:(NSString *)groupId;
//通过群ID获取群组详情
-(LTGroup *)getGroupWithGroupId:(NSString *)groupId;


//添加到我的群组操作
-(BOOL)AddMyGroup:(LTGroup *)group;
//得到所有群组列表
-(NSArray<LTGroup *> *)getMyGroupList;
//更新我的群组信息
-(void)updateMyGroups:(NSArray<LTGroup *> *)groups;




//好友配置信息操作
-(BOOL)AddORUpdateUserConfig:(LTUserConfig *)userConfig;

//删除好友配置操作
-(BOOL)deleteUserConfig:(NSString *)friendId;

//通过frinedId查询UserConfig
-(LTUserConfig *)getUserConfigWithfriendId:(NSString *)friendId;


//添加群组配置信息
-(BOOL)AddOrUpdateGroupConfig:(LTGroupConfig *)groupConfig;

//删除群组配置信息
-(BOOL)deleteGroupConfig:(NSString *)groupId;

//获取群组的配置信息
-(LTGroupConfig *)getGroupConfigWithGroupId:(NSString *)groupId;


//搜索

-(NSArray<LTUser *> *)getUserWithKeyWorld:(NSString *)keyworld;

-(NSArray<LTGroup *> *)getGroupWithKeyWorld:(NSString *)keyworld;







@end
